<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>
  <body onload="init()">
  	
  	<form action="#(contextPath)/h5/upload" method="post" enctype="multipart/form-data">
  		<p>上传文件:<input type="file" name="file"></p>
  		<p><input type="submit" value="保存"></p>
  	</form>
  	<hr>
	<p><input type="checkbox" name="permission" value="product:add">添加</p>
	<p><input type="checkbox" name="permission" value="product:update">编辑</p>
	<p><input type="checkbox" name="permission" value="product:delete">删除</p>
	<form action="#(contextPath)/admin/role/roleDispatch" method="post">
		<textarea id="result" name="permission"></textarea>
		<input type="submit" value="发送">
	</form>
  	<p><input type="text" id="msg"><input type="button" onclick="subsend()" value="发送"></p>
  	<p id="content"></p>
	<script src="//cdn.bootcss.com/jquery/3.1.1/jquery.js"></script>
    <script type="text/javascript">
		var ws;
		function init(){
		    ws = new WebSocket("ws://localhost:8080/crowdsourcing/websocket");
		    ws.onopen = function(evn){
		        console.log(evn);
		    };
		    ws.onmessage = function(evn){
		         var dv = document.getElementById("content");
		         dv.innerHTML+=evn.data+"<br>";
		    };
		    ws.onclose = function(){
		        console.log("关闭");
		    };
		};
		function subsend(){
		    var msg = document.getElementById("msg").value;
		    ws.send(msg);
		}
	</script>

  	<script>
		$(function () {
			$("input:checkbox[name=permission]").change(function() {
				var roleStr="admin";
				var permission={"role":roleStr,"permissions":[]}
				$('input:checkbox[name=permission]:checked').each(function (i) {
					permission.permissions.push(roleStr+":"+$(this).val());
				});
				var str = JSON.stringify(permission)
				$("#result").val(str);
			});
		});

	</script>
  </body>
</html>
